package com.jing.controller;

import com.jing.pojo.ReadingRooms;
import com.jing.pojo.Result;
import com.jing.pojo.SensorConfig;
import com.jing.service.SensorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 陈书憬
 * @version 1.0
 * 2024/9/28
 */
@RestController
@RequestMapping("/sensor")
public class SensorController {

    @Autowired
    private SensorService sensorService;


    @PostMapping("/add")
    public Result add(String roomId, String roomName, int dhtPin, int firePin, int ledPin) {
        sensorService.add(roomId, roomName, dhtPin, firePin, ledPin);
        return Result.success();

    }


    @GetMapping("/isSet")
    public Result getIsSet(Integer id) {
        sensorService.getIsSet(id);

        return Result.success();
    }


    @GetMapping("/selectRoom")
    public Result<List<SensorConfig>> selectRoom(Integer roomId) {

       List<SensorConfig>  sensorConfigs =  sensorService.selectRoom(roomId);

        return Result.success(sensorConfigs);
    }

    @PostMapping("/update")
    public Result update(String roomId, int dhtPin, int firePin, int ledPin) {
        sensorService.update(roomId, dhtPin, firePin, ledPin);
        return Result.success();

    }

    @GetMapping("/get")
    public Result<List<SensorConfig>> selectAllRoomsList() {
        List<SensorConfig> sc = sensorService.selectAllRoomsList();
        return Result.success(sc);
    }

}
